#include "debug.h"
#include "Utils/Rect.h"

NS_BEGIN(SDL)
NS_BEGIN(UTILS)

#pragma region CTOR & DTOR

Rect::Rect(Sint16 _x, Sint16 _y, Uint16 _w, Uint16 _h)
{
	//CTOR("Rect", this);
	m_rect.x = _x;
	m_rect.y = _y;
	m_rect.w = _w;
	m_rect.h = _h;
}

Rect::Rect(SDL_Rect const& _rect)
	: m_rect(_rect)
{
	//CTOR("Rect", this);
}

Rect::Rect(Rect const& _rect)
{
	//CTOR("Rect", this);
	*this = _rect;
}

Rect::~Rect()
{
	//DTOR("Rect", this);
}

#pragma endregion
#pragma region Operators

Rect& Rect::operator=(Rect const& _rect)
{
	if (this != &_rect)
	{
		m_rect = _rect.m_rect;
	}
	return (*this);
}

bool Rect::operator==(Rect const& _rect) const
{
	return (m_rect.x == _rect.m_rect.x && m_rect.y == _rect.m_rect.y &&
			m_rect.w == _rect.m_rect.w && m_rect.h == _rect.m_rect.h);
}

bool Rect::operator!=(Rect const& _rect) const
{
	return (m_rect.x != _rect.m_rect.x || m_rect.y != _rect.m_rect.y ||
			m_rect.w != _rect.m_rect.w || m_rect.h != _rect.m_rect.h);
}

#pragma endregion

void Rect::InitSDLRect(SDL_Rect& _rect, Sint16 _x, Sint16 _y,
					   Uint16 _w, Uint16 _h)
{
	_rect.x = _x;
	_rect.y = _y;
	_rect.w = _w;
	_rect.h = _h;
}

bool Rect::IsInArea(Rect const& _rect, Rect const& _area)
{
	bool condX = (_rect.GetX() >= _area.GetX() &&
				  _rect.GetX() + _rect.GetW() <= _area.GetX() + _area.GetW());
	bool condY = (_rect.GetY() >= _area.GetY() &&
				  _rect.GetY() + _rect.GetH() <= _area.GetY() + _area.GetH());
	return (condX && condY);
}

void Rect::ToSDLRect(SDL_Rect& _rect) const
{
	_rect = m_rect;
}

#pragma region Getters & Setters

SDL_Rect const& Rect::GetRect() const
{
	return (m_rect);
}

void Rect::SetRect(SDL_Rect const& _rect)
{
	m_rect = _rect;
}

Sint16 Rect::GetX() const
{
	return (m_rect.x);
}

void Rect::SetX(Sint16 _x)
{
	m_rect.x = _x;
}

Sint16 Rect::GetY() const
{
	return (m_rect.y);
}

void Rect::SetY(Sint16 _y)
{
	m_rect.y = _y;
}

Uint16 Rect::GetW() const
{
	return (m_rect.w);
}

void Rect::SetW(Uint16 _w)
{
	m_rect.w = _w;
}

Uint16 Rect::GetH() const
{
	return (m_rect.h);
}

void Rect::SetH(Uint16 _h)
{
	m_rect.h = _h;
}

#pragma endregion

NS_END(UTILS)
NS_END(SDL)
